import { IDispose } from "../../../../../com/gengine/core/IDispose";
import { MiniGameObject } from "../MiniGameObject";
import { FrameTimer } from "../../../../../com/gengine/core/frame/FrameTimer";
import { TimerType } from "../../../../../com/gengine/core/frame/TimerType";
import { SWFPlayer } from "../../../scene/modle/SWFPlayer";
import { ModelType } from "../../../scene/modle/data/ModelType";
import { Fish } from "./Obj/Fish";
import { Vector } from "../../../../../__AS3__/vec/Vector";
//class FishingScene
    
    export  class FishingScene /* flash.display.Sprite */ implements IDispose
    {
        constructor()
        {
            
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            graphics.beginFill(16777215, 0.01);
            graphics.drawRect(0, 0, FishingScene.AREAWIDTH, FishingScene.AREAHEIGHT);
            graphics.endFill();
            this.addSWFPlayer("bubble.swf", 80, 215);
            this.addSWFPlayer("bubble.swf", 200, 200);
            this.addSWFPlayer("bubble.swf", 360, 200);
            this.addSWFPlayer("bubble.swf", 660, 200);
            this.addSWFPlayer("bgFish1.swf", 340, 150);
            this.addSWFPlayer("bgFish2.swf", 165, 170);
            this.addSWFPlayer("bgFish1.swf", 360, 160);
            this.addSWFPlayer("bgFish2.swf", 185, 170);
            this.addSWFPlayer("bgFish2.swf", 270, 160);
            this.addSWFPlayer("grass1.swf", 630, 190);
            this.addSWFPlayer("grass2.swf", 488, 180);
            this.addSWFPlayer("grass3.swf", 200, 185);
            this.objList = new Vector.<MiniGameObject>();
            this.timer = new FrameTimer();
            this.timer.addListener(TimerType.ENTERFRAME, this.render);
            return;
        }

        /* internal  */addSWFPlayer(arg1: string, arg2: number, arg3: number): void
        {
            var loc1=null;
            (loc1 = new Object /* flash.display.Sprite */()).mouseChildren = false;
            loc1.mouseEnabled = false;
            var loc2;
            (loc2 = new SWFPlayer()).load(arg1, ModelType.Skill, null);
            loc1.addChild(loc2);
            loc1.x = arg2;
            loc1.y = arg3;
            this.addChild(loc1);
            return;
        }

        /* internal  */render(arg1: FrameTimer): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=this.objList;
            for(loc1 of loc3) 
            {
                loc1.Do();
                if (typeof !(loc1 === "fish")) 
                {
                    continue;
                }
                if (!(loc1.x < -1 * loc1.width || loc1.x > FishingScene.AREAWIDTH || loc1.y < -1 * loc1.height || loc1.y > FishingScene.AREAHEIGHT)) 
                {
                    continue;
                }
                this.delObject(loc1);
            }
            return;
        }

        public addObject(arg1: MiniGameObject): void
        {
            if (this.objList.indexOf(arg1) >= 0) 
            {
                return;
            }
            this.objList.push(arg1);
            addChild(arg1);
            return;
        }

        public delObject(arg1: MiniGameObject): void
        {
            var loc1=this.objList.indexOf(arg1);
            if (loc1 >= 0) 
            {
                this.objList.splice(loc1, 1);
            }
            if (arg1.parent && arg1.parent == this) 
            {
                removeChild(arg1);
            }
            arg1.dispose();
            return;
        }

        public addEffect(arg1: SWFPlayer, arg2: number=0, arg3: number=0): void
        {
            arg1.move(arg2, arg3);
            this.addChild(arg1);
            return;
        }

        public disposeEffect(arg1: SWFPlayer): void
        {
            arg1.dispose();
            return;
        }

        public start(): void
        {
            this.timer.start();
            return;
        }

        public stop(): void
        {
            this.timer.stop();
            return;
        }

        public get allObject(): Vector.<MiniGameObject>
        {
            return this.objList;
        }

        public dispose(arg1: Boolean=true): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=this.objList;
            for(loc1 of loc3) 
            {
                this.delObject(loc1);
            }
            this.timer.stop();
            this.timer = null;
            return;
        }

        protected /* var */objList: Vector.<MiniGameObject>;

        protected /* var */timer: FrameTimer;

        public static /* var */AREAWIDTH: number=600;

        public static /* var */AREAHEIGHT: number=400;
    }

            FishingScene.AREAWIDTH = 600;
            FishingScene.AREAHEIGHT = 400;
        